#include <iostream>
#include <algorithm>
#define MAXN 1005
#define MAXT 1000005
using namespace std;
int dp[MAXT];

struct range {
    int s, e, c;
    range() {}
    range(int _s, int _e, int _c): s(_s), e(_e), c(_c) {}
};

bool operator<(const range & r1, const range & r2) {
        return r1.s < r2.s;
    }

range rs[MAXN];
int N, M, R;
void solve();
int main() {
    cin >> N >> M >> R;
    int s, e, c;
    for (int i = 0; i < M; i++) {
        cin >> s >> e >> c;
        rs[i] = range(s, e, c);
    }
    solve();
}

void solve() {
    sort(rs, rs + M);
    for (int i = 0; i < M; i++) {
        range t = rs[i];
        dp[t.e] = max(dp[t.e], t.c);
        for (int j = 0; j <= i; j++) {
            if (rs[j].e + R <= t.s)
                dp[t.e] = max(dp[rs[j].e] + t.c, dp[t.e]);
        }
    }

    int res = 0;
    for (int i = 0; i <= N; i++) {
        res = max(res, dp[i]);
    }
    cout << res << endl;
}